急急急 jsp-->servlet乱码

来源:百度知道 编辑:UC知道 时间:2024/06/22 17:23:58
jsp提交中文数据 到servelt后 出现乱码 怎么解决?
数据库用的是sql server 2005
servlet在获取参数前都加了 request.setCharacterEncoding("utf-8");
页面都是统一的utf-8字符集
而且我用IE7正常,IE6乱码 奇怪

在jsp页面中加上
<%@ page contentType="text/html;charset=utf-8" %>

然后做一个filter

public class SetCharacterEncodingFilter implements Filter {

protected String encoding = null;

protected FilterConfig filterConfig = null;

protected boolean ignore = true;

public void destroy() {

this.encoding = null;
this.filterConfig = null;

}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
}

chain.doFilter(request, response);

}

pub